// ==================================================================================
// Shared Genomics Project MPI Codebase
// Version 1.0 30/04/2010
//
// (c) 2010 University of Manchester all rights reserved
//
// This file is distributed under the GNU General Public License, Version 2.  
// Please see the file COPYING.txt for more details
// ==================================================================================

#ifndef _MISSINGNESS_H_
#define _MISSINGNESS_H_

#include "mapfile.h"
#include "pedfile.h"
#include "options.h"

#ifdef __cplusplus
extern "C" {
#endif

/*!
\file
\ingroup	gio
\brief		Person Missingness Functions
\details	
	These functions calculate the missingness index (cf. MIND parameter of PLINK) 
	for each person in a genomic data-set.<br>
	The MIND indices are used by the parallelised filter code (see \ref bfilter.h).<br>
	The person missingness file uses the suffix SUFFIX_PERSON_MISSINGNESS .
*/

/*!
\brief Create a Person missingness file.
\details
	The genomic data in the \ref mapfile and \ref pedfile structures are scanned
	and the MIND indices calculated for each person in the genomic data-set.<br>
	The MIND values are then written to text file.<br>
	The output filename is a concatonation of \ref selected_options::ldir, \ref selected_options::szRunId
	and \ref SUFFIX_PERSON_MISSINGNESS.
\param [in] m mapfile structure
\param [in] p pedfile structure
\param [in] ops Output file location
\param [in] chromos Chromosomal model
\returns 1 on success, 0 on failure
*/
int missingnessfile_create(struct mapfile *m, struct pedfile *p, struct selected_options *ops, struct chromosomes *chromos);

/*!
\brief Load a person missingness file.
\details The input filename is bound to \ref selected_options::szMissingnessFileName .
\param [in] ops Input file location
\param [in] nSamples Pointer to store No. elements in missingness array
\returns double array or NULL on failure.
*/
double* missingnessfile_load(struct selected_options *ops, int *nSamples);

/*!
\brief Create a person missingness file and copy to a remote directory.
\details
	Simply a call to \ref missingnessfile_create() with the output file copied to a remote directory.<br>
	The output filename is a concatonation of \ref selected_options::rdir, \ref selected_options::szRunId
	and SUFFIX_PERSON_MISSINGNESS.<br>
\param [in] m mapfile structure
\param [in] p pedfile structure
\param [in] ops Output file location
\param [in] chromos Chromosomal model
\param [in] rank Local processor rank
\returns 1 on success, 0 on failure
*/
int missingnessfile_create_and_copy(struct mapfile *m, struct pedfile *p, struct selected_options *ops, struct chromosomes *chromos, int rank);

#ifdef __cplusplus
}
#endif

#endif // _MISSINGNESS_H_
